#include<iostream>
#include<memory>

//Implemetor实现接口
class Color {
    public:
        virtual void applyColor() = 0;
        virtual ~Color() = default;
};

class Red : public Color {
    public:
        void applyColor() override {
            std::cout << "Applying Red Color" << std::endl;
        }
};

class Green : public Color
{
public:
    void applyColor() override
    {
        std::cout << "Applying Green Color" << std::endl;
    }
};

// Abstraction 抽象类
class shape {
    protected:
        std::shared_ptr<Color> color;
    public:
        shape(std::shared_ptr<Color> c) : color(c) {}
        virtual void draw() = 0;
        virtual ~shape() = default;
};

class Circle : public shape {
    public:
    Circle(std::shared_ptr<Color> c) : shape(c) {}
    void draw() override {
        std::cout << "Drawing Circle with ";
        color->applyColor();
    }
};

class Square : public shape {
    public:
    Square(std::shared_ptr<Color> c) : shape(c) {}
    void draw() override {
        std::cout << "Drawing Square with ";
        color->applyColor();
    }
};


int main() {
    std::shared_ptr<Color> red = std::make_shared<Red>();
    std::shared_ptr<Color> green = std::make_shared<Green>();

    std::shared_ptr<shape> circle = std::make_shared<Circle>(red);
    std::shared_ptr<shape> square = std::make_shared<Square>(green);

    circle->draw();
    square->draw();

    return 0;
}